import * as appConfig from "../app-config.js";
function address(that, todo) {
  authorize(that, 'scope.address', todo, '需要微信授权才可以使用地址')
}
function authorize(that, setting, todo, title) {
  wx.getSetting({
    success: function success(res) {
      var authSetting = res.authSetting;
      if (authSetting[setting] == null) {
        //第一次授权
        wx.authorize({
          scope: setting,
          success() {
            todo(that);
          }
        })
      } else {
        if (!authSetting[setting]) {
          wx.openSetting({
            success: (res) => {
              if (!res.authSetting[setting]) {
                wx.showToast({
                  title: title,
                  icon: 'none'
                })
              } else {
                todo(that);
              }
            }
          })
        }
        else {
          todo(that);
        }
      }
    }
  });

}

function baseUrl(url,data,callBack){
  wx.request({
    url: appConfig.apiBase + url,
    data:data,
    success:function(res){
      console.log(res.data)
      callBack(res.data);
    }
  })
}


module.exports = {
  address: address,
  baseUrl: baseUrl
}

